/**
 * Created by Ji.wenjiang on 2016/8/27.
 */


angular.module('inspinia')
  .controller('modelForm', function ($scope,_undefined,_undefinedToVoid,$window) {
        init();
    function init() {
      $scope.modelForm=JSON.parse(localStorage.getItem('modelMessages'));
      $scope.modelForm.gender=$scope.modelForm.gender==0?'男':'女';
      switch ($scope.modelForm.payType){
        case '1':
          $scope.modelForm.payType= '自费';
          break;
        case '2':
          $scope.modelForm.payType= '公费';
          break;
        case '3':
          $scope.modelForm.payType= '住院';
          break;
      }
      var myDate=new Date();
      $scope.modelForm.year=myDate.getFullYear();
      $scope.modelForm.month=myDate.getMonth()+1;
      $scope.modelForm.day=myDate.getDate();
      $scope.modelSelect1={};
      $scope.modelSelects=[];
    }
    $scope.addModelMessage=function (type) {

     if(type==1){
      if(_undefined($scope.modelSelect.modelPart)){
        $scope.modelPart='';
      }else{
        $scope.modelPart=$scope.modelSelect.modelPart;
      }
       if(_undefined($scope.modelSelect.modelAttachment)){
         $scope.modelSelect.modelAttachment='';
       }
       // _undefinedToVoid($scope.modelSelect.pattern);
      var data = {"type":$scope.modelType,"detailMessages":'部件：'+$scope.modelPart+','+'附件：'+$scope.modelSelect.modelAttachment+','+
       '模具：'+_undefinedToVoid($scope.modelSelect.pattern)+','+'补充说明：'+_undefinedToVoid($scope.modelSelect.textarea),"modelNum":Date.parse(new Date())};
       $scope.modelSelects.push(data);
     }else if(type==2){
       var data = {"type":$scope.modelType,"detailMessages":_undefinedToVoid($scope.modelSelect.organize),"modelNum":Date.parse(new Date())};

       $scope.modelSelects.push(data);
     }else{
       var data = {"type":$scope.modelType,"detailMessages":_undefinedToVoid($scope.modelSelect.metal),"modelNum":Date.parse(new Date())};
       $scope.modelSelects.push(data);
     }
    }
    $scope.remove=function (item) {
     $.each($scope.modelSelects,function (i,val) {
       if(item==val){
         $scope.modelSelects.splice(i,1);
         return false;
       }
     })
    }
    $scope.save=function () {
      $scope.hidetable=true;
    }
    $scope.save1=function () {
      $scope.hidetable=true;
      setTimeout(function () {
        if($scope.hidetable==true){
          $window.print();
        }
      },100)
    }
    $scope.edit=function () {
      $scope.hidetable=false;
    }
  })
